// pages/screens/stat/stat.js
const app = getApp();
const screenservice = require("../../../apiservice/screen/screenservice.js");
const screenteamservice = require("../../../apiservice/screen/screenteamservice.js");
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startdate:"2019-06-10",
    enddate:"2019-08-19",
    screenGroup:"筛查一组",
    screenOwner:"LouisLu",
	  screenTeam:{},
	  screenStatistics:{},
  },

  // 获取筛查小组信息
   async getScreenTeamAndStatistics(userid) {
	var that = this;
  	var scteam =await screenteamservice.GetFirstScreenTeam(userid);
	that.setData({
		screenTeam:scteam.data
	});
	this.getScreenStatistics();
  },
  
  //获取筛查统计信息
  async getScreenStatistics(){
	  var that = this;
	  var endDate = that.data.enddate;
	  var startDate = that.data.startdate;
	  var screenteamid = that.data.screenTeam.new_screenteamId;
	  var statistics =await screenservice.QryScreenStatisticsBy(screenteamid,startDate,endDate);
	  that.setData({
	  		 screenStatistics:statistics.data
	  });
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var currDate = util.getCurrentMonthDate();
    this.setData({
      startdate:currDate.starttime,
      enddate:currDate.endtime
    });
	  var currentUserId = app.globalData.userInfo.userid;
	  this.getScreenTeamAndStatistics(currentUserId);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindStartDateChange:function(e){
      this.setData({
        startdate: e.detail.value
      });
    var currentUserId = app.globalData.userInfo.userid;
    this.getScreenTeamAndStatistics(currentUserId);
    },
  bindEndDateChange:function(e){
    this.setData({
      enddate: e.detail.value
    });
    var currentUserId = app.globalData.userInfo.userid;
    this.getScreenTeamAndStatistics(currentUserId);
  },
  
})